import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'


Vue.config.productionTip = false;
//加载全局组件
import PageView from "./components/PageView.vue"
Vue.component("PageView", PageView);
import Loading from "./components/Loading.vue"
Vue.component("loading", Loading);
import PreviewImage from "./components/PreviewImage.vue"
Vue.component("previewImage", PreviewImage);
import SlideMenu from "./components/SlideMenu.vue"
Vue.component("slideMenu", SlideMenu);



//加载swiper插件
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper);
//加载懒加载模块
import VueLazyload from 'vue-lazyload'
import lazyLoading from "./assets/img/lazyloading.jpg"
import error from "./assets/img/error.gif"
Vue.use(VueLazyload, {
  error: error,
  loading: lazyLoading,
})
//加载axios插件
import axios from "axios"
const axiosInstance = axios.create({
  baseURL: "https://www.softeem.xin"
})
Vue.prototype.$http = axiosInstance;
//加载弹窗插件
import {Alert, Confirm, Toast} from 'wc-messagebox'
import 'wc-messagebox/style.css'

Vue.use(Alert)
Vue.use(Confirm)
Vue.use(Toast,{
  duration:2000
})

//注册全局自定义指令
Vue.directive("longpress", {
  bind(el, binding, vNode) {
    let timerId = null;
    let ts = (event) => {
     let str = event.currentTarget;
      if (timerId == null) {
        timerId = setTimeout(() => {
          if (typeof binding.value == "function") {
            //自定义属性去取事件绑定者
            event.click=str;
            binding.value(event);
          }
          else{
            throw new Error("请传入一个方法");
          }
        }, 500)
      }
    };
    let te = (event) => {
      if (timerId != null) {
        clearTimeout(timerId);
        timerId = null;
      }
    }
    el.addEventListener("touchstart", ts);
    el.addEventListener("touchend", te);
    el.addEventListener("touchcancel", te);
    el.addEventListener("touchmove", te);
  }
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
